package com.atcumt.Huawei;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

/*
 * 合并表记录
 * 4
 * 0 1
 * 0 2
 * 1 2
 * 3 4
 * 
 * 输出：
 * 0 3
 * 1 2
 * 3 4
 */
public class HJ12 {
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int k = scanner.nextInt();
            int v = scanner.nextInt();
            if (map.containsKey(k)) {
                map.put(k, map.get(k) + v);
            } else {
                map.put(k, v);
            }
        }
        Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, Integer> next = iterator.next();
            System.out.println(next.getKey() + " " + next.getValue());
        }
    }
}
